package com.qf.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.support.SessionStatus;

import javax.servlet.http.HttpSession;

/**
 *
 * 演示一个Session的使用
 * @author lixu
 */
@Controller
@SessionAttributes({"gender","name"})
//代表：gender或name 只要在request域中有 就会同步到Session中
public class SessionController {


    @GetMapping("/session")
    public String sessionTest(Model model){//, //HttpSession httpSession){

        //底层放到request对象中了
        model.addAttribute("name","xixi");
        model.addAttribute("nnn","xixi");
        //httpSession.setAttribute("name","xixi");
        //  ${sessionScope.name} 就有了
        return "hello";
    }
    @RequestMapping("/hello2")
    public String hello(SessionStatus status){
        // 移除通过SessionAttributes存入的session
        status.setComplete();
        return "index";
    }
}
